home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13737 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: news.cybercomm.net!usenet
  2. From: "J. Mark Hord" <pajtim@cybercomm.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: exit() and flushing data to ofstream files?
  5. Date: Tue, 26 Mar 1996 21:01:00 -0500
  6. Organization: CyberComm Online Services
  7. Message-ID: <3158A15C.58F7@cybercomm.net>
  8. References: <31584F18.29B2@apldbio.com>
  9. NNTP-Posting-Host: sl-010.sl.cybercomm.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
  14.  
  15. Nasser Abbasi wrote:
  16. > hi,
  17. > I am confused about something.
  18. > according to "the C++ programming language", Bjarne Stroustrup
  19. > page 85 it says:
  20. > "..This can be done by calling exit(), which first clean things
  21. > like output streams."
  22. > I take this as meaning that calling exit() from your C++
  23. > program will cause buffers to be flushed out to ofstream
  24. > files . well, this does no seem to be the case, this little
  25. > program shows that exit() do not flush data to file.
  26.  
  27. I think it simply means that the destructor(s) will be called - the 
  28. destructor may or may not flush but they do close the stream (or file).
  29.  
  30. > #include <fstream.h>
  31. > #include <stdlib.h>
  32. > main()
  33. > {
  34. > ofstream  f;
  35. >  f.open("tmp1");
  36. >  f.put('X');
  37. >  //f.flush();
  38. >   exit(1);       // this does not flush data to file
  39. >  return 1;
  40. > }
  41. > Now looking at tmp I see no data in it.
  42. > This is on Sun Solaris 2.5, using CC compiler.
  43.  
  44. Unfortunately, I do not have a copy of VC++ here at home or I would 
  45. check to see how that handles it.
  46.  
  47. > What is the recommended way to terminate the program
  48. > and have all buffers flushed automatically without having
  49. > to explicity call flush() on each open stream file ?
  50.  
  51. Try the ios::unitbuf flag for flushing after each insertion and 
  52. ios::stdio for flushing after each extraction. 
  53.  
  54. > Is this a bug or a feature of exit() ?
  55. > thanks,
  56. > Nasser
  57. > Applied BioSystems
  58.